package sk.tonyb.library.collection;

import java.util.ArrayList;
import java.util.List;

/** 
 * Class, which contains additional methods used for work with lists. 
 *  
 * @author Anton Balucha
 * @since 14.10.2011
 * @last_modified 16.10.2011
 */
public class ListProcessor {
	
	/** Constructor. */
	public ListProcessor() {}
	
	/** 
	 * Method, which creates copy of of entered source list. <br>
	 * 
	 * @param source - source list, which is not null and size of this list is > 0. <br>
	 * @return
	 * list - copy of source. <br>
	 * null - if source is null, if size of source is not > 0, if some error occurs. <br>
	 */
	public synchronized List<String> copy(List<String> source) {
		return this.append(source, new ArrayList<String>());
	}
	
	/** 
	 * Method, which append source list to destination. <br>
	 * 
	 * @param source - source list - not null and size is > 0; <br>
	 * @param destination - destination list - not null. Size can be equals to zero. <br> 
	 * @return
	 * destination - destination list with appended source. <br>
	 * null - if source is null, size of source is 0, destination is null, some error occurs. <br>
	 */
	public synchronized List<String> append(List<String> source, List<String> destination) {
		
		if(source != null && source.size() > 0 && destination != null) {
	
			for(int i = 0; i < source.size(); i++) {
				destination.add(source.get(i));
			}
			
			return destination;
		}
		
		else {
			return null;
		}
	}
	
	/** 
	 * Method, which convert list of string as List to list of strings as String[]. <br>
	 * 
	 * @param source - list of strings, which will be converted. <br>
	 * @return 
	 * destination - converted list of links as String[]. <br>
	 * null - if entered parameter is null, empty or some error occurs. <br>
	 */
	public synchronized String[] convert(List<String> source) {
		
		String[] destination = null;
		
		if(source != null && source.size() > 0) {

			destination = new String[source.size()];
			
			for(int i = 0; i < source.size(); i++) {
				destination[i] = source.get(i);
			}
		}
		
		return destination;
	}
}
